#include "stdafx.h"
#include "ConsBlockData.h"
#include "dmBlockData.h"
#include "BlockData.h"
using namespace Dimine::Entity;

dmConsBlockDataCS::dmConsBlockDataCS()
{
	m_native=dmConsBlockData::New();
}
bool dmConsBlockDataCS::Save(STRINGCS filename)
{
	VALIDATE_NATIVE
	String2Char(filename)
	return m_native->Save(fn);
}
bool dmConsBlockDataCS::Load(STRINGCS filename)
{
	VALIDATE_NATIVE
	String2Char(filename)
	return m_native->Load(fn);
}
dmBlockAttributeCollectionCS^ dmConsBlockDataCS::QueryCell(double x,double y,double z)
{
	dmBlockAttributeCollectionCS^ atts=gcnew dmBlockAttributeCollectionCS();
	if(!m_native) return atts;
	double pt[3]={x,y,z};
	BLOCK_ATT_VALUE* att=new BLOCK_ATT_VALUE;
	int n=0;
	if(m_native->QueryCell(pt,att,n)>0&&n>0)
	{
		for(int i=0;i<n;++i)
		{
			BLOCK_ATT_VALUE* at= &att[i];
			atts->Add(gcnew dmBlockAttributeCS(gcnew System::String(at->attName),at->value));
		}
		return atts;
	}
	return atts;
}
double dmConsBlockDataCS::ComputeMetalQuantity(STRINGCS attName, double density)
{
	if(!m_native) return -1;
	String2Char(attName)
	return m_native->ComputeMetalQuantity(fn,density);
}
int dmConsBlockDataCS::ComputeOreAndRockQuantity(STRINGCS attName, double% ore,double% rock,double% metal,double oreDensity,double rockDensity)
{
	if(!m_native) return -1;
	String2Char(attName)
	double n_ore=ore;
	double n_rock=rock;
	double n_metal=metal;
	int res=m_native->ComputeOreAndRockQuantity(fn,n_ore,n_rock,n_metal,oreDensity,rockDensity);
	ore=n_ore;
	rock=n_rock;
	metal=n_metal;
	return res;
}